package com.school.service.Impl;

import com.school.entity.AdminUser;
import com.school.mapper.AdminUserMapper;
import com.school.service.AdminUserService;
import com.school.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminUserServiceImpl implements AdminUserService {

    @Autowired
     AdminUserMapper adminUserMapper;

    @Override
    public AdminUser login(String userName, String password) {
        // 可选：使用 MD5 加密密码后再查询
        String encryptedPassword = MD5Util.MD5Encode(password, "UTF-8");

        return adminUserMapper.findByUserNameAndPassword(userName, encryptedPassword);
    }

    @Override
    public AdminUser getUserDetailById(Integer userId) {
        return adminUserMapper.selectById(userId);
    }

    @Override
    public int updateName(Integer userId, String loginUserName, String nickName) {
        AdminUser adminUser = adminUserMapper.selectById(userId);
        if (adminUser != null){
            adminUser.setLoginUserName(loginUserName);
            adminUser.setNickName(nickName);
        }
        return adminUserMapper.updateById(adminUser);
    }


}
